/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2024-11-23 18:25:27
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-06-26 12:26:52
 * @FilePath: /backend/shorthand-modules/shorthand-modules-front/src/main/java/com/angus/modules/front/service/impl/FrontConfigServiceImpl.java
 */
package com.angus.modules.front.service.impl;

import com.angus.common.core.constant.CacheConstants;
import com.angus.common.core.text.Convert;
import com.angus.common.core.utils.StringUtils;
import com.angus.common.redis.service.RedisService;
import com.angus.modules.front.domain.FrontConfig;
import com.angus.modules.front.mapper.FrontConfigMapper;
import com.angus.modules.front.repository.FrontConfigRepository;
import com.angus.modules.front.service.IFrontConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liyanan
 * @date 2024/10/15 5:41 PM
 * @description
 */
@Service
public class FrontConfigServiceImpl extends ServiceImpl<FrontConfigMapper, FrontConfig> implements IFrontConfigService {

    @Resource
    private FrontConfigRepository frontConfigRepository;

    @Autowired
    private RedisService redisService;

    @Override
    public List<FrontConfig> selectConfigList(FrontConfig config) {
        return null;
    }

    @Override
    public String selectConfigByKey(String configKey) {
        String configValue = Convert.toStr(redisService.getCacheObject(getCacheKey(configKey)));
        if (StringUtils.isNotEmpty(configValue))
        {
            return configValue;
        }
        FrontConfig retConfig = frontConfigRepository.getConfigByKey(configKey);
        if (StringUtils.isNotNull(retConfig)) {
            redisService.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
            return retConfig.getConfigValue();
        }
        return StringUtils.EMPTY;
    }

    @Override
    public boolean checkConfigKeyUnique(FrontConfig config) {
        return false;
    }

    @Override
    public int insertConfig(FrontConfig config) {
        return 0;
    }

    @Override
    public String selectConfigById(Long configId) {
        return null;
    }

    @Override
    public int updateConfig(FrontConfig config) {
        return 0;
    }

    @Override
    public void deleteConfigByIds(Long[] configIds) {

    }

    @Override
    public void resetConfigCache() {

    }



    /**
     * 设置cache key
     *
     * @param configKey 参数键
     * @return 缓存键key
     */
    private String getCacheKey(String configKey)
    {
        return CacheConstants.SYS_CONFIG_KEY + configKey;
    }
}
